package com.baichang.taoshunda.controller.mobile.delivery;

import com.baichang.framework.controller.BaseMobileController;
import com.baichang.framework.controller.IService;
import com.baichang.framework.excelption.ServiceException;
import com.baichang.taoshunda.controller.ControllerConstants;
import com.baichang.taoshunda.service.UserBankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by ${wushenglu} on 17/09/05.
 */
@Controller
@RequestMapping(ControllerConstants.BANKCARD)
public class BankCardMCtronller extends BaseMobileController {
    @Autowired
    private UserBankService userBankService;

    /**
     * 修改商家的银行卡信息
     *
     * @param request
     * @param response
     */
    @RequestMapping("/updateBankCard")
    public void updateBankCard(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest request, HttpServletResponse response, String json) throws ServiceException {
                Integer bankId = getInt(json, "bankId", 0);
                Integer bankTypeId = getInt(json, "bankTypeId", 0);
                String bankNo = getString(json, "bankNo", "");
                return userBankService.updateBankCard(bankId, bankTypeId, bankNo);
            }
        });
    }

    /**
     * 解绑银行卡
     *
     * @param request
     * @param response
     */
    @RequestMapping("/unBundling")
    public void unBundlingByDisId(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest request, HttpServletResponse response, String json) throws ServiceException {
                Integer disId = getInt(json, "disId", 0);
                Integer bankId = getInt(json, "bankId", 0);
                return userBankService.unBundlingByDisId(disId, bankId);
            }
        });
    }
/**
 * 检查银行卡是否绑定
 *  disId     商家编号
 * cardTypeId 银行编号
 *  cardNumber 银行卡号
 *
 */
@RequestMapping("/checkBundling")
public void checkBundling(HttpServletRequest request, HttpServletResponse response) {
    initEncode(request, response, new IService() {
        @Override
        public Object init(HttpServletRequest request, HttpServletResponse response, String json) throws ServiceException {
            Integer disId = getInt(json, "disId", 0);
            Integer bankId = getInt(json, "cardTypeId", 0);
            String cardNumber = getString(json, "cardNumber", "");
            return userBankService.checkBundlingByDisId(disId, bankId,cardNumber);
        }
    });
}
    /**
     * 查看配送员的银行卡信息
     *
     * @param request
     * @param response
     */
    @RequestMapping("/findDeliveryBankCard")
    public void findDeliveryBankCard(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest request, HttpServletResponse response, String json) throws ServiceException {
                Integer disId = getInt(json, "disId", 0);
                return userBankService.findDeliveryBankCard(disId);
            }
        });
    }

    /**
     * 添加配送员银行卡
     *
     * @param request
     * @param response
     */
    @RequestMapping("/addDeliveryBankCard")
    public void addBankCard(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest request, HttpServletResponse response, String json) throws ServiceException {
                Integer deliveryId = getInt(json, "deliveryId", 0);
                Integer cardTypeId = getInt(json, "cardTypeId", 0);
                String cardNumber = getString(json, "cardNumber", "");
                String userName = getString(json, "userName", "");
                return userBankService.addDeliveryBankCard(deliveryId, cardTypeId, cardNumber, userName);
            }
        });
    }

    /**
     * 查看开户行列表
     *
     * @param request
     * @param response
     */
    @RequestMapping("/findBankList")
    public void findBankList(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest request, HttpServletResponse response, String json) throws ServiceException {
                return userBankService.findBank();
            }
        });
    }

}
